package com.ddzh.ratelimit;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@Component
public class IpKeyResolver implements KeyResolver {
    /**
     * 用ip地址的令牌桶key
     * @param exchange
     * @return
     */
    @Override
    public Mono<String> resolve(ServerWebExchange exchange) {
        Mono<String> key = Mono.just(exchange.getRequest().getRemoteAddress().getHostName());
        System.out.println("key = " + key);
        return key;
    }
}
